﻿using DemoUser.Application.User.Filter;
using DemoUser.Core;
using DemoUser.Core.Loggings;

using Furion;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SqlSugar;

namespace DemoUser.Web.Core
{
    public class Startup : AppStartup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            ////引入输出到控制台日志依赖
            //services.AddConsoleFormatter(options =>
            //{
            //    options.WithTraceId = true;
            //    options.WithStackFrame = true;
            //});

            ////引入输出到文件日志依赖
            //services.AddFileLogging();

            //引入输出到数据库日志依赖
            services.AddDatabaseLogging<DBLoggingWriter>();

            //全局授权
            //services.AddJwt<JwtHandler>(enableGlobalAuthorize:true);

            //引入jwt依赖
            services.AddJwt<JwtHandler>();

            services.AddCorsAccessor();

            services.AddControllers()
                    .AddInjectWithUnifyResult();
            services.AddSqlsugarSetup(App.Configuration);
            //services.Configure<MvcOptions>(options =>
            //{
            //    options.Filters.Add<WangActionFilter>();
            //});
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseCorsAccessor();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseInject(string.Empty);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}
